import requests
import json


def query_express_by_phone(phone_number, api_key):
    url = "https://api.kuaidi100.com/express/query"
    headers = {
        "Content-Type": "application/json"
    }
    data = {
        "com": "auto",  # 快递公司代码，auto表示自动识别
        "num": "",  # 快递单号，这里留空
        "phone": phone_number,
        "key": api_key
    }

    response = requests.post(url, headers=headers, data=json.dumps(data))

    if response.status_code == 200:
        result = response.json()
        if result['status'] == '200':
            return result['data']
        else:
            return f"查询失败: {result['message']}"
    else:
        return f"请求失败，状态码: {response.status_code}"


if __name__ == "__main__":
    api_key = "your_api_key_here"  # 替换为你的API Key
    phone_number = "18799169074"  # 替换为要查询的手机号
    result = query_express_by_phone(phone_number, api_key)
    print(result)